package Bank;

import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Transaction {
    //todo сделать чтобы в поле инициатор был не номер счета и айди юзера.
    public enum transactionStatus {waiting, inProgress, success, fail, notEnoughMoney}

    private BigInteger id;
    private Account src;
    private Account target;
    private User initiator;
    private double summ;
    private Date date;
    private transactionStatus status;

    public Transaction(BigInteger id, Account src, Account target, User initiator, double summ, Date date) {
        this.id = id;
        this.src = src;
        this.target = target;
        this.initiator = initiator;
        this.summ = summ;
        this.date = date;
        this.status = transactionStatus.waiting;
    }

    public Transaction(BigInteger id, Account src, Account target, User initiator, double summ, Date date, transactionStatus status) {
        this.id = id;
        this.src = src;
        this.target = target;
        this.initiator = initiator;
        this.summ = summ;
        this.date = date;
        this.status = status;
    }

    public Account getSrc() {
        return src;
    }

    public Account getTarget() {
        return target;
    }

    public User getInitiator() {
        return initiator;
    }

    public double getSumm() {
        return summ;
    }

    public Date getDate() {
        return date;
    }

    public String getStringDate() {
        DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        return df.format(date);
    }

    public transactionStatus getStatus() {
        return status;
    }

    public void setStatus(transactionStatus status) {
        this.status = status;
    }

    public BigInteger getId() {
        return id;
    }

    @Override
    public String toString() {
        return "Transaction{" +
                "id=" + id +
                ", src=" + src.getId() +
                ", target=" + target.getId() +
                ", initiator=" + initiator.getId() +
                ", summ=" + summ +
                ", date=" + date +
                ", status=" + status +
                '}';
    }
}